package com.taptech.doufu.ui.viewholder.personalcenter;

import android.content.Context;
import android.os.Handler;
import android.view.View;
import android.view.ViewGroup;

import com.taptech.doufu.util.TTLog;
import com.taptech.doufu.bean.BaseBean;
import com.taptech.doufu.bean.personalcenter.PersonalBaseAccount;

import java.util.List;

/**
 * Created by lsy on 2015/9/24.
 */
public class SearchListViewAdapter extends MessageListViewAdapter {

    public SearchListViewAdapter(Context mContext) {
        super(mContext);
    }

    public SearchListViewAdapter(Context mContext, List<? extends BaseBean> dataList, BaseAdapterViewHolder viewHolder) {
        super(mContext, dataList, viewHolder);
    }

    public SearchListViewAdapter(Context mContext, List<? extends BaseBean> dataList, BaseAdapterViewHolder viewHolder, Handler handler) {
        super(mContext, dataList, viewHolder, handler);
    }

    public SearchListViewAdapter(Context mContext, List<? extends BaseBean> dataList, PersonalBaseAccount account, BaseAdapterViewHolder viewHolder) {
        super(mContext, dataList, account, viewHolder);
    }

    public SearchListViewAdapter(Context mContext, List<? extends BaseBean> dataList, BaseViewHolderFactory viewHolderFactory) {
        super(mContext, dataList, viewHolderFactory);
    }

    public SearchListViewAdapter(Context mContext, List<? extends BaseBean> dataList, PersonalBaseAccount account, BaseViewHolderFactory viewHolderFactory) {
        super(mContext, dataList, account, viewHolderFactory);
    }

    public SearchListViewAdapter(Context mContext, List<? extends BaseBean> dataList, PersonalBaseAccount account, BaseViewHolderFactory viewHolderFactory, Handler handler) {
        super(mContext, dataList, account, viewHolderFactory, handler);
    }

    protected String searchKeyWord = "";

    public void setSearchKeyWord(String keyWord){
        this.searchKeyWord = keyWord;
    }

    private int singlePage = 0;


    public void setSinglePage(int singlePage) {
        this.singlePage = singlePage;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        int viewType = getItemViewType(position);

        TTLog.d("tag", "note list is ======" + viewType);
        if (convertView == null)
        {
            if (viewHolders != null && mDataList != null && viewType >= 0)
            {
                viewHolders[viewType] = mViewHolderFactory.createViewHolder(mContext, mDataList.get(position), position);
                viewHolders[viewType].setHandler(messageHandler);
                convertView = viewHolders[viewType].getConvertView();
                viewHolders[viewType].getChildView(convertView);
                convertView.setTag(viewHolders[viewType]);
            } else if (viewHolder != null)
            {
                viewHolder = viewHolder.createViewHolder(mContext, position);
                viewHolder.setHandler(messageHandler);
                convertView = viewHolder.getConvertView();
                viewHolder.getChildView(convertView);
                convertView.setTag(viewHolder);
            }

        } else
        {
            if (viewHolders != null)
            {
                viewHolders[viewType] = (BaseAdapterViewHolder) convertView.getTag();
            } else if (viewHolder != null)
            {
                viewHolder = (BaseAdapterViewHolder) convertView.getTag();
            }

        }
        if (position >= mDataList.size())
        {
            return convertView;

        }
        if (viewHolders != null && mDataList != null && viewType >= 0)
        {
            if (searchKeyWord != null){
                viewHolders[viewType].setChildView(mDataList.get(position) , searchKeyWord,singlePage);
            }
            else {
                viewHolders[viewType].setChildView(mDataList.get(position),singlePage);
            }

        } else if (viewHolder != null)
        {
            if (searchKeyWord != null){
                viewHolder.setChildView(mDataList.get(position) , searchKeyWord,singlePage);
            }else {
                viewHolder.setChildView(mDataList.get(position),singlePage);
            }
        }

        return convertView;
    }
}
